package com.lijy.list;

import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

public class TreeSetTest {
    public static void main(String[] args) {
        SortedSet<Item> parts = new TreeSet<Item>();
        parts.add(new Item("Cindy", 12));
        parts.add(new Item("Amy", 10));
        parts.add(new Item("Bob", 9));
        parts.add(new Item("Bob", 13));

        System.out.println(parts);

        SortedSet<Item> sortByDescription = new TreeSet<Item>(
                new Comparator<Item>() {
                    public int compare(Item a, Item b) {
                        String descrA = a.getDescription();
                        String descrB = b.getDescription();
                        return descrA.compareTo(descrB);
                    }
                }
        );

        sortByDescription.addAll(parts);
        System.out.println(sortByDescription);

    }
}
